li_key="31e2e9ede61f2f81638ca15063de2984"

def geocode(address,city=None,batch="false",sig=None,output="JSON",callback=None):
    """获取地理编码"""
    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
        'key': li_key,
        'address':address,
         "city":city,
         "batch":batch,
         "sig":sig,
         "output":output,
         "callback":callback
    }
    response = requests.get(url,params = params)
    data = response.json()
    return data


def regeocode(location,poitype=None,radius=1000,extensions="base",batch="false",roadlevel=None,sig=None,output="JSON",callback=None,homeorcorp=0):
    """获取逆地理编码"""
    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'
    params={
        "key": li_key,
        "location":location,
        "poitype":poitype,
        "radius":radius,
        "extensions":extensions,
        "batch":batch,
        "roadlevel":roadlevel,
        "sig":sig,
        "output":output,
        "callback":callback,
        "homeorcorp":homeorcorp
    }
    response = requests.get(url,params=params)
    data = response.json()
    return data


def walk_design(origin, destination, sig=None, output="JSON", callback=None):
    """路径规划"""
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    params = {
        'key': li_key,
        'origin': origin,
        'destination': destination,
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


def bus_design(origin,destination,city,cityd=None,extensions='base',strategy=None,nightflag=0,date=None,time=None,sig=None)->dict:
    """公交路径规划"""
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    params={
        'key':li_key,
        'origin':origin,
        'destination':destination,
        'city':city,
        'cityd':cityd,
        'extensions':extensions,
        'strategy':strategy,
        'nightflag':nightflag,
        'date':date,
        'output':'json'
    }
    response = requests.get(url,params=params)
    data = response.json()
    return data


def car(origin,destination,strategy=10,waypoints=None,avoidpolygons=None,):
    """驾车路径规划"""
    url = "https://restapi.amap.com/v3/direction/driving?parameters"
    params = {
        'key':li_key,
        'origin':origin,
        'destination':destination,
        'strategy':strategy,
        'waypoints':waypoints,
        'avoidpolygons':avoidpolygons,
        'output':'json'
    }
    response = requests.get(url,params=params)
    date = response.json()
    return date


def area_search(key, keywords=None, subdistrict=1, page=1, offset=20, extensions="base", filter=None, output="JSON",
                callback=None):
    """行政区域查询"""
    url = "https://restapi.amap.com/v3/config/district?parameters"
    params = {
        "key": li_key,
        "keywords": keywords,
        "subdistrict": subdistrict,
        "page": page,
        "offset": offset,
        "extensions": extensions,
        "filter": filter,
        "output": 'json',
        "callback": callback
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


def area_search(key, keywords=None, subdistrict=1, page=1, offset=20, extensions="base", filter=None, output="JSON",
                callback=None):
    """行政区域查询"""
    url = "https://restapi.amap.com/v3/config/district?parameters"
    params = {
        "key": li_key,
        "keywords": keywords,
        "subdistrict": subdistrict,
        "page": page,
        "offset": offset,
        "extensions": extensions,
        "filter": filter,
        "output": 'json',
        "callback": callback
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


def POI_search(key, keywords=None, types=None, city=None, citylimit="false", children=0, offset=20, page=1,
               extensions="base", sig=None, output="JSON", callback=None):
    """关键字搜索"""
    url = "https://restapi.amap.com/v3/place/text?parameters"
    params = {
        "key": li_key,
        "keywords": keywords,
        "types": types,
        "city": city,
        "citylimit": citylimit,
        "children": children,
        "offset": offset,
        "page": page,
        "extensions": extensions,
        "sig": sig,
        "output": output,
        "callback": callback
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


def around_search(key, location, keywords=None, types=None, city=None, radius=3000, sortrule="distance", offset=20,
                  page=1, extensions="base", sig=None, output="JSON", callback=None):
    """周边搜索"""
    url = "https://restapi.amap.com/v3/place/around?parameters"
    params = {
        "key": li_key,
        "location": location,
        "keywords": keywords,
        "types": types,
        "city": city,
        "radius": radius,
        "sortrule": sortrule,
        "offset": offset,
        "page": page,
        "extensions": extensions,
        "sig": sig,
        "output": output,
        "callback": callback
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result



def various_search(key,polygon,keywords,types=None,city=None,offset=20,page=1,extensions="base",sig=None,output="JSON",callback=None):
    """多边形搜索"""
    url="https://restapi.amap.com/v3/place/polygon?parameters "
    params = {
        "key":li_key,
        "polygon":polygon,
        "keywords":keywords,
        "types":types,
        "city":city,
        "offset":offset,
        "page":page,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(url,params=params)
    data = r.json()
    return data


def IP_located(key, ip, sig=None, output="JSON"):
    """IP定位"""
    url = "https://restapi.amap.com/v3/ip?parameters"
    params = {
        "key": li_key,
        "ip": ip,
        "sig": sig,
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


from PIL import Image
from io import BytesIO
import requests


def static_map(key, location, zoom, size=None, scale=1, markers=None, labels=None, paths=None, traffic=0, page=None,
               sig=None):
    """静态地图"""
    url = "https://restapi.amap.com/v3/staticmap?parameters"
    params = {
        "key": li_key,
        "location": location,
        "zoom": zoom,
        "size": size,
        "scale": scale,
        "markers": markers,
        "labels": labels,
        "paths": paths,
        "traffic": traffic,
        "sig": sig,
        "output": "json"
    }

    r = requests.get(url, params=params)
    data = Image.open(BytesIO(r.content))
    return data


def location_change(key, locations, coordsys="autonavi", sig=None, output="JSON"):
    """坐标转换"""
    url = " https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    params = {
        "key": li_key,
        "locations": locations,
        "coordsys": coordsys,
        "sig": sig,
        "output": output
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


def weather_search(key, city, extensions=None, output="JSON"):
    """天气查询"""
    url = " https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
        "key": li_key,
        "city": city,
        "extensions": extensions,
        "output": output
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


def input_tips(key, keywords, type=None, location=None, city=None, citylimit="true", datatype="all", sig=None,
               output="JSON", callback=None):
    """输入提示"""
    url = "https://restapi.amap.com/v3/assistant/inputtips?parameters"
    params = {
        "key": li_key,
        "keywords": keywords,
        "type": type,
        "location": location,
        "city": city,
        "citylimit": citylimit,
        "datatype": datatype,
        "sig": sig,
        "output": output,
        "callback": callback
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


